package com.cardbaobao.cardbabyclient.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.cardbaobao.cardbabyclient.R;
import com.cardbaobao.cardbabyclient.utils.ScreenUtil;

/**
 * Created by Jiangzx on 2018/3/1 14:07.
 */

public class NormalDialog extends Dialog {
    private TextView tvTitle;
    private TextView tvContent;
    private TextView tvLeft;
    private TextView tvRight;
    public interface ButtonListener{
        void onLeftBtClicked(NormalDialog dialog);
        void onRightBtClicked(NormalDialog dialog);
    }
    public NormalDialog(@NonNull Context context) {
        this(context, R.style.Theme_Dialog_From_Bottom);
    }

    private ButtonListener listener;

    public NormalDialog setButtonListener(ButtonListener listener){
        this.listener=listener;
        return NormalDialog.this;
    }

    public void setTitle(String title){
        if(!TextUtils.isEmpty(title)){
            tvTitle.setText(title);
        }
    }

    public void setContent(String content){
        if(!TextUtils.isEmpty(content)){
            tvContent.setText(content);
        }
    }

    public void setLeftButton(String left){
        if(!TextUtils.isEmpty(left)){
            tvLeft.setText(left);
        }
    }

    public void setRightButton(String right){
        if(!TextUtils.isEmpty(right)){
            tvRight.setText(right);
        }
    }

    public NormalDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        setContentView(R.layout.dialog_normal);
        tvTitle= (TextView) findViewById(R.id.tv_title);
        tvContent= (TextView) findViewById(R.id.tv_content);
        tvLeft= (TextView) findViewById(R.id.tv_left);
        tvRight= (TextView) findViewById(R.id.tv_right);
        tvLeft.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(listener!=null){
                    listener.onLeftBtClicked(NormalDialog.this);
                }
            }
        });
        tvRight.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(listener!=null){
                    listener.onRightBtClicked(NormalDialog.this);
                }
            }
        });
        //设置宽高
        Window window=getWindow();
        if(window!=null){
            WindowManager.LayoutParams params=window.getAttributes();
            params.width=(int) (ScreenUtil.getScreenWidth()*0.8f);
            params.height= WindowManager.LayoutParams.WRAP_CONTENT;
            window.setAttributes(params);
        }
        //设置动画

        //点击不可取消
        setCancelable(false);
    }
}
